package com.durian.house.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.durian.system.api.domain.house.PremisesInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.durian.common.log.annotation.Log;
import com.durian.common.log.enums.BusinessType;
import com.durian.common.security.annotation.RequiresPermissions;
import com.durian.house.service.IPremisesInfoService;
import com.durian.common.core.web.controller.BaseController;
import com.durian.common.core.web.domain.AjaxResult;
import com.durian.common.core.utils.poi.ExcelUtil;
import com.durian.common.core.web.page.TableDataInfo;

/**
 * 楼盘信息Controller
 * 
 * @author durian
 * @date 2022-06-22
 */
@RestController
@RequestMapping("/info")
public class PremisesInfoController extends BaseController
{
    @Autowired
    private IPremisesInfoService premisesInfoService;

    /**
     * 查询楼盘信息列表
     */
    @RequiresPermissions("house:info:list")
    @GetMapping("/list")
    public TableDataInfo list(PremisesInfo premisesInfo)
    {
        startPage();
        List<PremisesInfo> list = premisesInfoService.selectPremisesInfoList(premisesInfo);
        return getDataTable(list);
    }

    /**
     * 导出楼盘信息列表
     */
    @RequiresPermissions("house:info:export")
    @Log(title = "楼盘信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PremisesInfo premisesInfo)
    {
        List<PremisesInfo> list = premisesInfoService.selectPremisesInfoList(premisesInfo);
        ExcelUtil<PremisesInfo> util = new ExcelUtil<PremisesInfo>(PremisesInfo.class);
        util.exportExcel(response, list, "楼盘信息数据");
    }

    /**
     * 获取楼盘信息详细信息
     */
    @RequiresPermissions("house:info:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(premisesInfoService.selectPremisesInfoById(id));
    }

    /**
     * 新增楼盘信息
     */
    @RequiresPermissions("house:info:add")
    @Log(title = "楼盘信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PremisesInfo premisesInfo)
    {
        return toAjax(premisesInfoService.insertPremisesInfo(premisesInfo));
    }

    /**
     * 修改楼盘信息
     */
    @RequiresPermissions("house:info:edit")
    @Log(title = "楼盘信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PremisesInfo premisesInfo)
    {
        return toAjax(premisesInfoService.updatePremisesInfo(premisesInfo));
    }

    /**
     * 删除楼盘信息
     */
    @RequiresPermissions("house:info:remove")
    @Log(title = "楼盘信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(premisesInfoService.deletePremisesInfoByIds(ids));
    }
}
